function getGoodsNameByGid(gid) {

    var gname = "";
    switch (parseInt(gid)) {
        case 1:
            gname = "招兵令";
            break;
        case 2:
            gname = "招贤令";
            break;
        case 3:
            gname = "将军令";
            break;
        case 4:
            gname = "大将军令";
            break;
        case 5:
            gname = "体力丹";
            break;
        case 6:
            gname = "副将经验书";
            break;
        case 7:
            gname = "原矿";
            break;
        case 8:
            gname = "精矿";
            break;
        case 9:
            gname = "珍矿";
            break;
        case 10:
            gname = "1级技能书";
            break;
        case 11:
            gname = "2级技能书";
            break;
        case 12:
            gname = "3级技能书";
            break;
        case 13:
            gname = "4级技能书";
            break;
        case 14:
            gname = "5级技能书";
            break;
        case 15:
            gname = "小银袋";
            break;
        case 16:
            gname = "银两";

            break;
        case 17:
            gname = "金币";
            break;
    }
    return gname;

}
function getGoodsIdByGname(gname) {

    var gid = 0;
    switch (gname) {
        case "招兵令":
            gid = 1;
            break;
        case "招贤令":
            gid = 2;
            break;
        case "将军令":
            gid = 3;
            break;
        case "大将军令":
            gid = 4;
            break;
        case "体力丹":
            gid = 5;
            break;
        case "副将经验书":
            gid = 6;
            break;
        case "原矿":
            gid = 7;
            break;
        case "精矿":
            gid = 8;
            break;
        case "珍矿":
            gid = 9;
            break;
        case "1级技能书":
            gid = 10;
            break;
        case "2级技能书":
            gid = 11;
            break;
        case "3级技能书":
            gid = 12;
            break;
        case "4级技能书":
            gid = 13;
            break;
        case "5级技能书":
            gid = 14;
            break;
        case "小银袋":
            gid = 15;
            break;
        case "银两":
            gid = 16;
            break;
        case "金币":
            gid = 17;
            break;
    }
    return gid;

}
function getCurrentMsgType() {
    const triggerTabList = document.querySelectorAll('#myTab button[class="nav-link active"]')
    const ele = triggerTabList[0];
    if (ele.id == "home-tab")
        return 0;
    else if (ele.id == "profile-tab")
        return 1;
    else if (ele.id == "contact-tab")
        return 2;

    else if (ele.id == "disabled-tab")
        return 3;
}
function getMsgidByType(type) {
    if (type == 0)
        return "home-tab";
    else if (type == 1)
        return "profile-tab";
    else if (type == 2)
        return "contact-tab";
    else
        return "disabled-tab";
}
function getJobNameByJobId(jid) {
    var jname = "武士";
    var jnames = ["武士", "术士", "文人", "商人", "常人"];
    jname = jnames[parseInt(jid)];
    return jname;
}


function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
    var context = "";
    if (r != null)
        context = decodeURIComponent(r[2]);
    reg = null;
    r = null;
    return context == null || context == "" || context == "undefined" ? "" : context;
}


function getKvFromCookie(key) {
    var obj = JSON.parse($.cookie("user"));
    return obj[key];
}
function getKvFromCookieBag(key) {
    var ret = 0;
    var objlist = JSON.parse($.cookie("bag"));
    for (let index = 0; index < objlist.length; index++) {
        if (objlist[index].goods_id == key) {
            ret = objlist[index].counts;
            break;
        }
    }
    return ret;;
}
function setKvFromCookieUser(key, val) {
    var userobj = JSON.parse($.cookie("user"));
    userobj[key] = val;
    $.cookie("user", JSON.stringify(userobj));
}

  //update userinfo
function setKvFromCookieBag(key, val) {
    var baglist = JSON.parse($.cookie("bag"));
    for (let index = 0; index < baglist.length; index++) {
        if(baglist[index]["goods_id"] == key){
            baglist[index]["counts"] = parseInt(val);
            break;
        }
      }
      $.cookie("bag",JSON.stringify(baglist));
}

function generateRandomInteger(min, max) {
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

function mytime() {
    let time = new Date();
    let timeInfo =
        (time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds())
    return timeInfo;
}
function getCountsAndGidObj(index) {

    var retjson = "";
    var baoshiTypes = ["钻石", "白玉", "翡翠", "珍珠", "琥珀", "水晶"];
    var yuanshiTypes = ["原矿", "精矿", "珍矿"];
    var kuangshiTypes = ["金矿", "银矿", "铁矿"];
    var baowuTypes = ["招兵令", "招贤令", "大将军令", "将军令", "小银袋", "体力丹", "副将经验书"];
    if (index == 0) {
        var counts = generateRandomInteger(100, 5000);
        var gid = getGoodsIdByGname("银两");
        retjson = "{\"counts\":" + counts + ",\"gid\":" + gid + "}";

    }

    else if (index == 1) {
        var counts = generateRandomInteger(5, 40);
        var gid = getGoodsIdByGname("金币");
        retjson = "{\"counts\":" + counts + ",\"gid\":" + gid + "}";
    }

    else if (index == 2) {
        var counts = 1;
        var gid = getGoodsIdByGname(generateRandomInteger(1, 5) + "级技能书");
        retjson = "{\"counts\":" + counts + ",\"gid\":" + gid + "}";

    }

    else if (index == 3 || index == 4) {
        var counts = generateRandomInteger(100, 5000);
        var gid = getGoodsIdByGname("银两");
        retjson = "{\"counts\":" + counts + ",\"gid\":" + gid + "}";

    }

    //return "一个"+generateRandomInteger(1,6)+"级"+baoshiTypes[generateRandomInteger(0,baoshiTypes.length-1)];
    else if (index == 5) {
        var counts = 1;
        var gid = getGoodsIdByGname(yuanshiTypes[generateRandomInteger(0, yuanshiTypes.length - 1)]);
        if(gid ==9){
            msgMgr.net.sendMsg("1000","系统",getKvFromCookie("name")+"运气太好了,挖到一个珍矿",3,()=>{
                msgMgr.net.getMsgByType(3);
            });
        }
        retjson = "{\"counts\":" + counts + ",\"gid\":" + gid + "}";

    }

    else if (index == 6) {
        var counts = 1;
        var gid = getGoodsIdByGname(baowuTypes[generateRandomInteger(0, baowuTypes.length - 1)]);
        retjson = "{\"counts\":" + counts + ",\"gid\":" + gid + "}";

    }

    return retjson;
}
function getOutStr(index) {
    var obj = JSON.parse(getCountsAndGidObj(index));

    netSendAddGoods(obj.gid, obj.counts)
    if (index == 0 || index == 1 || index == 3 || index == 4) {

        return obj.counts + getGoodsNameByGid(obj.gid);
    } else {
        return "一个" + getGoodsNameByGid(obj.gid);
    }
}